<template>
  <div class="mod-config">

      <el-button-group style="margin-bottom: 10px;">
        <el-button icon="el-icon-search" type="primary" @click="searchHandle">查询</el-button>
        <el-button icon="el-icon-delete" type="primary" @click="searchReset">清空</el-button>
        <el-button v-if="permissions.eims_eimscustomerfeedback_add" icon="el-icon-plus" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-button-group>
      <el-form inline @keyup.enter.native="searchHandle">
        <el-form-item label="会员卡号">
          <el-input v-model="dataForm.customerCard"></el-input>
        </el-form-item>
        <el-form-item label="顾客姓名">
          <el-input v-model="dataForm.customerName"></el-input>
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input v-model="dataForm.phone1"></el-input>
        </el-form-item>
        <el-form-item label="操作人姓名">
          <el-input v-model="dataForm.createUsername"></el-input>
        </el-form-item>
        <el-form-item label="操作时间">
          <el-row>
            <el-col :span="11">
              <el-date-picker v-model="dataForm.createTimeMin" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
            </el-col>
            <el-col class="line" :span="2" style="text-align: center;">-</el-col>
            <el-col :span="11">
              <el-date-picker v-model="dataForm.createTimeMax" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
      <div class="avue-crud" style="margin-top: 5px;">
        <el-table :data="dataList" border v-loading="dataListLoading" :max-height="tableHeight">
          <el-table-column prop="customerCard" label="会员卡号"></el-table-column>
          <el-table-column prop="customerName" label="会员姓名"></el-table-column>
          <el-table-column prop="changeIntegral" label="赠送积分"></el-table-column>
          <el-table-column prop="createUsername" label="操作人"></el-table-column>
          <el-table-column prop="createTime" label="操作时间"></el-table-column>
          <el-table-column label="操作" width="180" fixed="right">
            <template slot-scope="scope">
              <el-button type="text" icon="el-icon-collection" @click="checkDetailHandle(scope.row.id)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="avue-crud__pagination">
        <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next">
        </el-pagination>
      </div>
    <!-- 弹窗，添加 -->
    <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshData="getDataList"></table-form>
    <!-- 弹窗，详情 -->
    <detail-dialog v-if="detailVisible" ref="detailDialog"></detail-dialog>
  </div>
</template>

<script>
  import { mapGetters } from "vuex"
  import { filterParams } from '@/util/tools'
  import { customerComplaintFetchList, customerComplaintDelObj } from "@/api/eims/customer-complaint"
  import { getCustomerIntegralChageList } from "@/api/eims/customer-integral"

  import TableForm from "./form"
  import DetailDialog from "./detail"

  export default {
    data() {
      return {
        dataForm: {},
        dataList: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        addOrUpdateVisible: false,
        detailVisible: false
      };
    },
    components: {
      TableForm,
      DetailDialog
    },
    created() {
      this.getDataList();
    },
    computed: {
      ...mapGetters(["permissions"]),
      tableHeight: function(){
        return window.innerHeight - 260
      }
    },
    methods: {
      //  查询数据
      searchHandle() {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true;
        let params1 = {
          current: this.pageIndex,
          size: this.pageSize
        }
        let params2 = filterParams(this.dataForm)
        getCustomerIntegralChageList(Object.assign(params1, params2)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        });

      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getDataList();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getDataList();
      },
      // 清空搜索框
      searchReset() {
        this.dataForm = {};
      },
      // 查看积分变更详情
      checkDetailHandle(id) {
        this.detailVisible = true;
        this.$nextTick(() => {
          this.$refs.detailDialog.init(id);
        });
      },
      // 新增 / 修改
      addOrUpdateHandle(id) {
        this.addOrUpdateVisible = true;
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id);
        });
      }
    }
  };
</script>
